The first option to use a module is with the command import
followed by the module name.
import math
Whenever we want to use a function from that module we have to do it by writing the libraty name followed by a dot (.
) and the function.
If you write math.
and use the Tab key, that should show a list with the functions that are part of the module.
In [ ]:
import math
In [ ]:
math.
In [ ]:
# we can use now some function
math.sin(math.pi/2)
In [ ]:
from math import sin
In [ ]:
sin(1.0)
However, you cannot use pi
because it has not been imported
In [ ]:
sin(pi/2)
you could import it in the same way as we did with sin
In [ ]:
from math import sin, pi # now pi is available
In [ ]:
sin(pi/2)
In [ ]:
import math as mt
You can then use the following to see the documentation of a function
In [ ]:
mt.sin?
In [ ]:
import random
In [ ]: